/* 
 * File:   Agent.h
 * Author: ben
 *
 * Created on November 2, 2012, 1:29 PM
 */

#ifndef AGENT_H
#define	AGENT_H

/*
 * 1) Functions to move to an adjacent cell
 * 2) Random number generator          - Now seperate class ( Random )
 * 3) Function to pick up a particle   - In environment class
 * 4) Function to put down a particle  - In environment class
 * 5) Initialize
 *      * Seed random number generator - In Random class
 *      * Reset environment
 * 6) Sleep for x time between each iteration - Sleep variable in Synch
 * 7) Terminate
 */

#include "Synch.h"
#include "Thread.h"
#include "Particle.h"
#include <string>

#define THREAD_NAME_LENGTH 100
#define CHANCE_PLACE_PARTICLE 40
#define CHANCE_TAKE_PARTICLE 60

class Agent : public Thread {
private:
    Synch *m_mySynch;
    char m_myName[THREAD_NAME_LENGTH];
    int m_Row;
    int m_Column;
    Particle* m_pickedParticle;
    static pthread_mutex_t moveLocker;
    static pthread_mutex_t cellLocker;
public:
    /**
     * Defaults constructor
     * @param name Name of Agent
     * @param s Synch object with purpose of synchronizing threads
     * @param row Starting row number
     * @param col Starting column number
     */
    Agent(const char *name, Synch *s, int row, int col);
    /**
     * Moves an agent randomly one cell in any direction. If edge of board is
     * encountered, agent moves in opposite direction.
     */
    void moveAgent();
    /**
     * This is the function that does all the heavy lifting of this lab.
     * It randomly places, moves, and then picks up a particle
     */
    void run();
    /**
     * Acessor to moveLocker mutex
     * @return Mutex moveLocker 
     */
    static pthread_mutex_t getMoveLocker() { return moveLocker; }
};

#endif	/* AGENT_H */

